package com.example.myfragment;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView one = findViewById(R.id.one);
        TextView two = findViewById(R.id.two);
        one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment left = new LeftFragment();
                androidx.fragment.app.FragmentManager fm = getSupportFragmentManager();
                androidx.fragment.app.FragmentTransaction b = fm.beginTransaction();
                b.replace(R.id.hello, left);
                b.commit();
                one.setBackgroundColor(Color.WHITE);
                two.setBackgroundColor(Color.rgb(247,248,249));
            }
        });
        two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fragment second = new SecondFragment();
                androidx.fragment.app.FragmentManager fm = getSupportFragmentManager();
                androidx.fragment.app.FragmentTransaction b = fm.beginTransaction();
                b.replace(R.id.hello, second);
                b.commit();
                one.setBackgroundColor(Color.rgb(247,248,249));
                two.setBackgroundColor(Color.WHITE);
            }
        });
    }
}